package com.zhangpeng520.user.controller;

import com.zhangpeng520.user.dao.UserMapper;
import com.zhangpeng520.user.entity.User;
import com.zhangpeng520.user.service.UserService;
import com.zhangpeng520.user.service.UserServipml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/8/7 0007.
 */
@Controller
@RequestMapping("user")
public class UserController {




   @Autowired
   private UserService userService;

    @RequestMapping("/index")
    public String getUser()
    {

        return "login";
    }


    /**
     *
     *@Author zhangpeng(www.zhangpeng520.com)
     *@Date 2017/8/11 0011 12:36
     *@Desripition 跳转到home页
     *
     */
    @RequestMapping("/home")
    public String getHome()
    {


        return "home";
    }


   /**
    *
    *@Author zhangpeng(www.zhangpeng520.com)
    *@Date 2017/8/13 0013 15:13
    *@Desripition 获取用户信息
    *
    */

    @RequestMapping("/userinfo")
    @ResponseBody
    public User getuser(HttpSession session)
    {
       User user=(User)session.getAttribute("loginInfo");
        System.out.println(user.getRealName());
       return user;
    }


    /**
     *
     *@Author zhangpeng(www.zhangpeng520.com)
     *@Date 2017/8/13 0013 12:06
     *@Desripition 进入主页后加载数据
     *
     */
    @ResponseBody
    @RequestMapping("/homedata")
    public String getHomedata(HttpServletRequest request, ModelMap map)
    {

        String username=request.getParameter("username");
        User user=userService.finduser(username);
        map.addAttribute("user",user);
        return "user";
    }

}
